package demo.day10

// usb 接口实现类
// 接口里面的所有成员 和 接口本身都是public open的 所以不需要open
// 接口不能有构造函数
fun main() {
    println(Mouse().insertUSB())
    val keyBoard = KeyBoard()
    keyBoard.usbVersionInfo = "123"
    keyBoard.usbInsertDevice = "456"
    println(keyBoard.insertUSB())
}

interface IUsb {
    var usbVersionInfo: String
    var usbInsertDevice: String
    fun insertUSB(): String
}

// 实现类不仅仅要重写接口的函数 也要重写接口的成员
class Mouse(override var usbVersionInfo: String = "USB3.0",
            override var usbInsertDevice: String = "鼠标接入了USB口") : IUsb {
    override fun insertUSB(): String {
        return "${usbVersionInfo} ${usbInsertDevice} 鼠标已经插入，识别成功"
    }
}

class KeyBoard: IUsb{
    override var usbVersionInfo: String = "USB2.0"
        get() = field
        set(value) {
            field = value
        }
    override var usbInsertDevice: String = "键盘键盘"
        get() = field
        set(value) {
            field = value
        }

    override fun insertUSB(): String {
        return "${usbVersionInfo} ${usbInsertDevice} 键盘已经识别，插入成功"
    }

}